﻿using Autofac;
using PLCWpfTest.Common;
using PLCWpfTest.Common.Extensions;
using PLCWpfTest.Models;
using PLCWpfTest.ViewModels;
using System.Windows;
using System.Windows.Controls;
using YWM;

namespace PLCWpfTest.Views
{
    /// <summary>
    /// ParameterSettingPage.xaml 的交互逻辑
    /// </summary>
    public partial class ParameterSettingPage : Page
    {
        private ParameterSettingViewModel _parameterSettingViewModel;
        public ParameterSettingPage()
        {
            InitializeComponent();
            DataContext = _parameterSettingViewModel = YApp.Resolve<ParameterSettingViewModel>();
        }

        private void GroupButton_Click(object sender, RoutedEventArgs e)
        {
            GroupConfigWindow groupConfigWindow = YApp.Resolve<GroupConfigWindow>();
            groupConfigWindow.ShowDialog();
        }

        private void VariableButton_Click(object sender, RoutedEventArgs e)
        {
            VariableConfigWindow variableConfigWindow = YApp.Resolve<VariableConfigWindow>();
            variableConfigWindow.ShowDialog();
        }

        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            _parameterSettingViewModel.Dispose();
        }

        private void StationDisplay_VariableDoubleClick(ParameterModel parameter)
        {
            if (!CommunicationCache.Connected)
            {
                this.ShowWarning("通信设备连接失败");
                return;
            }
            ParameterUpdateWindow parameterUpdateWindow = YApp.Resolve<ParameterUpdateWindow>(new NamedParameter("parameter", parameter));
            parameterUpdateWindow.ShowDialog();
        }
    }
}